﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LittleBoxes
{
    public enum ConnectionPointPanelStyle { Bidirectional, Input, Output };

    partial class ConnectionPointPanel : UserControl
    {
        public ConnectionPointPanel()
        {
            InitializeComponent();
        }

        public ConnectionPointPanelStyle Style 
        {
            set
            {
                if (value == ConnectionPointPanelStyle.Input)
                {
                    this.BuildConnectionPoint = delegate { return new InputConnectionPoint(); };
                }
                else if (value == ConnectionPointPanelStyle.Output)
                {
                    this.BuildConnectionPoint = delegate { return new OutputConnectionPoint(); };
                }
                else
                {
                    this.BuildConnectionPoint = delegate { return new ConnectionPoint(); };
                }
            }
        }

        private delegate ConnectionPoint ConnectionPointFactory();
        private ConnectionPointFactory BuildConnectionPoint;

        public virtual void Add(string description)
        {
            ConnectionPoint cp = this.BuildConnectionPoint();
            cp.Description = description;
            this.tableLayoutPanel1.Controls.Add(cp);
        }

        public virtual void Add()
        {
            this.Add("");
        }

        public void Remove(ConnectionPoint connPoint)
        {
            this.tableLayoutPanel1.Controls.Remove(connPoint);
        }

        /// <summary>
        /// Gets or sets the number of ConnectionPoints in this panel.  
        /// WARNING: setting this property will remove ALL existing ConnectionPoints, including those defined manually.
        /// </summary>
        public int Count
        {
            get
            {
                return this.tableLayoutPanel1.Controls.Count;
            }
            
            set
            {
                this.tableLayoutPanel1.Controls.Clear();
                for (int i = 0; i < value; i++)
                {
                    this.Add();
                }
            }
        }
    }
}
